From c133672258eaeb9880e2d27a097315441898331f Mon Sep 17 00:00:00 2001 From: Kalita Alexey Date: Mon, 23 Jan 2017 11:45:11 +0300 Subject: [PATCH] Added information about examples as libraries to the documentation --- src/doc/guide.md | 2 +- src/doc/manifest.md | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/doc/guide.md b/src/doc/guide.md index c26a830d7..32ff74e8f 100644 --- a/src/doc/guide.md +++ b/src/doc/guide.md @@ -238,7 +238,7 @@ Cargo project: * The default executable file is `src/main.rs`. * Other executables can be placed in `src/bin/*.rs`. * Integration tests go in the `tests` directory (unit tests go in each file they're testing). -* Example executable files go in the `examples` directory. +* Examples go in the `examples` directory. * Benchmarks go in the `benches` directory. These are explained in more detail in the [manifest diff --git a/src/doc/manifest.md b/src/doc/manifest.md index aebf1a282..5a61c741d 100644 --- a/src/doc/manifest.md +++ b/src/doc/manifest.md @@ -427,7 +427,7 @@ is a library, name the main source file `src/lib.rs`. Cargo will also treat any files located in `src/bin/*.rs` as executables. Your project can optionally contain folders named `examples`, `tests`, and -`benches`, which Cargo will treat as containing example executable files, +`benches`, which Cargo will treat as containing examples, integration tests, and benchmarks respectively. ```notrust @@ -451,13 +451,19 @@ To structure your code after you've created the files and folders for your proje Files located under `examples` are example uses of the functionality provided by the library. When compiled, they are placed in the `target/examples` directory. -They must compile as executables (with a `main()` function) and load in the -library by using `extern crate `. They are compiled when you run +They may compile either as executables (with a `main()` function) or as libraries. +They load in the library by using `extern crate `. They are compiled when you run your tests to protect them from bitrotting. -You can run individual examples with the command `cargo run --example +You can run individual executable examples with the command `cargo run --example `. +Specify `crate-type` to make an example be compiled as a library: +```toml +[[example.example]] +crate-type = ["staticlib"] +``` + # Tests When you run `cargo test`, Cargo will: -- 2.30.2